﻿@{
    ViewBag.Title = "Chợ Yêu Cầu";
    Layout = "~/Views/Shared/_Layout2.cshtml";

    //var param = ViewData["paramforpv"];
    //var titleprop = param.GetType().GetProperty("title");
    //var locationprop = param.GetType().GetProperty("location");
    //var categoryprop = param.GetType().GetProperty("category");
    var titlefilter = Request.Params["paramtitle"];
    var locationfilter = Request.Params["paramlocation"];
    var categoryfilter = Request.Params["paramcategory"];
    var listCate = ViewData["AllCate"] as List<SmallJob.Model.Category>;
}
<style>
    .request-detail-container {
        display: block;
        padding: 10px;
        border-bottom: 1px solid #dcd0d0;
    }

    .request-detail-toparea {
    }

    .request-detail-midarea {
    }

    .request-detail-botarea {
    }

    .request-detail-price {
        text-align: right;
    }

    .request-detail-enddate {
        text-align: right;
    }

    .request-detail-title a {
        text-decoration: none;
        font-weight: bolder;
    }

    .request-detail-info {
    }

    .request-search-container {
        width: 100%;
        height: auto;
        display: block;
        padding: 10px;
        border: 1px solid #dcd0d0;
    }

    .request-filter-container {
    }

    .request-detail-paging {
        text-align: right;
		padding-right: 10px;
    }
	#request-list-box {
		border: 1px solid #dcd0d0;
	}
</style>
<div style="margin-top: 50px;" class="row-fluid">
    <div class="span1"></div>
    <div class="span7" id="request-list-box">
        @{Html.RenderAction("ListRequestPV", ViewData["paramforpv"]);}
    </div>
    <div class="span3">
        <div class="request-search-container">
			<p><a class="btn btn-primary" href="/them-yeu-cau">Đăng tin cần người</a></p>
            @using (Html.BeginForm("Show", "Request", FormMethod.Post, new { Class = "form-inline", id = "filter-title-form" }))
            {
                <input type="hidden" name="page" value="1" />
                <input type="text" id="filter-title" placeholder="Nhập từ khóa" class="span7" value="@titlefilter"/>
                <input type="submit" value="Tìm kiếm" class="btn" />
            }
			<label>Địa điểm</label>
            <select name="location" id="filter-location">
                <option value="0" selected="@(string.IsNullOrWhiteSpace(locationfilter) ? "selected" : "")">Tất cả</option>
                @foreach (var item in SmallShop.Services.Implements.UtilityService.GetCities())
                {
                    if (locationfilter != null && locationfilter.Equals(item.Name))
                    {
                    <option value="@item.Name" selected="selected">@item.Name</option>
                    }
                    else
                    {
                    <option value="@item.Name">@item.Name</option>
                    }

                }
            </select>
			<label>Danh mục</label>
            <select name="cateID" id="filter-category">
                <option value="0" selected="@(string.IsNullOrWhiteSpace(categoryfilter) ? "selected" : "")">Tất cả</option>
                @foreach (var item in listCate)
                {
                    if (categoryfilter != null && categoryfilter.Equals(item.ID.ToString()))
                    {
                     <option value="@item.ID" selected="selected">@item.Name</option>
                    }
                    else
                    {
                    <option value="@item.ID">@item.Name</option>
                    }
                }
            </select>
            <br />
            <input type="button" value="Xem" class="btn" onclick="triggerfilternormal()" />
        </div>
    </div>
</div>
@using (Html.BeginForm("Show", "Request", FormMethod.Post, new { id = "hidden-filter" }))
{
    <input type="hidden" name="page" value="0" />
    <input type="hidden" name="paramlocation" />
    <input type="hidden" name="paramcategory" />
    <input type="hidden" name="paramtitle" />
}
<script>
    function collectdata() {
        var form = $('#hidden-filter');
        var location = $('#filter-location').val();
        if (location != '0') {
            $(form).find('[name=paramlocation]').val(location);
        } else {
            $(form).find('[name=paramlocation]').val('');
        }

        var category = $('#filter-category').val();
        if (category != '0') {
            $(form).find('[name=paramcategory]').val(category);
        } else {
            $(form).find('[name=paramcategory]').val('');
        }

        var title = $('#filter-title').val();
        if (title != '') {
            $(form).find('[name=paramtitle]').val(title);
        } else {
            $(form).find('[name=paramtitle]').val('');
        }

    }
    function triggerfilternormal() {
        $('#hidden-filter').find('[name=page]').val(1);
        collectdata();
        $.post("/Request/ListRequestPV", $('#hidden-filter').serialize(), function (data) {
            $('#request-list-box').html(data);
        })
    }
    $('#filter-title-form').submit(function (e) {
        e.preventDefault();
        triggerfiltertitle();
    });
    function triggerfiltertitle() {
        var title = $('#filter-title').val();
        $('#hidden-filter').find('[name=page]').val(1);
        var form = $('#hidden-filter');
        if (title != '') {
            $(form).find('[name=paramtitle]').val(title);
        } else {
            return;
        }
        $(form).find('[name=paramlocation]').val('');
        $(form).find('[name=paramcategory]').val('');
        //$(form).submit();
        $.post("/Request/ListRequestPV", $('#hidden-filter').serialize(), function (data) {
            $('#request-list-box').html(data);
        })
    }
</script>
